package main

import (
	"encoding/csv"
	"fmt"
	"io"
	"os"

	"github.com/axgle/mahonia"
)

func main() {
	fp, err := os.Open("test.csv")
	if err != nil {
		return
	}
	srcCoder := mahonia.NewDecoder("gb18030")

	reader := csv.NewReader(fp)
	record, err := reader.Read()
	for err != io.EOF {
		if err != nil {
			return
		}
		for _, gbstring := range record {
			utf8String := srcCoder.ConvertString(gbstring)
			fmt.Printf("%v", utf8String)
		}
		fmt.Printf("%v", "\n")
		record, err = reader.Read()
	}

	fp, err = os.Create("wTest.csv")
	if err != nil {
		return
	}
	writer := csv.NewWriter(fp)
	writer.Write(record)
}
